package Test1;

import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TestClient {
    public static void main(String[] args) {
        Socket socket = null;
        OutputStream os = null;
        try {
            //1、要知道服务器的地址和端口号
            InetAddress serverIP = InetAddress.getByName("127.0.0.1");
            int port = 9999;

            //2、创建socket连接
            socket = new Socket(serverIP, port);

            //3、发送消息 IO流
            os = socket.getOutputStream();
            os.write("你好，我是金冬天".getBytes());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (socket != null) {
                try {
                    socket.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

